import length from "../rule";

let validateLength = (value, callback, key, valueLength) => {
    let result = ''
    switch (key) {
        case 'dataItem':
            result = Math.min(Number(valueLength), length.DATA_ITEM_LENGTH)
            break;
        case 'dataId':
            result = Math.min(Number(valueLength), length.DATA_ID_LENGTH)
            break;
        case 'dataExt':
            result = Math.min(Number(valueLength), length.DATA_EXT_LENGTH)
            break;
        case 'dataDesc':
            result = Math.min(Number(valueLength), length.DATA_DESC_LENGTH)
            break;
        default:
            result = Math.min(Number(valueLength), length.EXT_LENGTH)
    }
    if (value && String(value).length > result) {
        callback(new Error('输入字符长度超过限制：' + result));
    } else {
        callback();
    }
};

export {validateLength}
